package com.jianyun.jyzs.presenter;


import android.content.Context;
import android.util.Log;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.jianyun.jyzs.model.LoginModel;
import com.jianyun.jyzs.model.imdoel.IJyLoginHelper;
import com.jianyun.jyzs.view.iview.ILoginView;

/**
 * Created by yangshijun on 2018/5/24.
 * 登录 presenter
 */

public class LoginPresenter extends MvpBasePresenter<ILoginView> {

    /**
     * 获取建云中心URL方法
     * @param enterpriseCode 企业号
     * @param username 用户名
     * @param password 密码
     */
    public void getJyCenterURL(Context context,String enterpriseCode, String username, String password){
        if (!isViewAttached()){
            return;
        }
        getView().showLoading();
        LoginModel.getInstance().getJyCenterUrl(context, enterpriseCode, new IJyLoginHelper.OnGetJyUrlListener() {
            @Override
            public void loginResult(boolean b, String msg) {
                Log.i("test","获取URL："+msg);
                getView().getCenterUrl(b,msg);
            }
        });
    }

    /**
     * 登录
     * @param enterpriseCode
     * @param username
     * @param password
     * @param appVersion
     *
     */
    public void startLogin(String enterpriseCode, String username, String password,
                           String appVersion){
        getView().showLoading();
        LoginModel.getInstance().startLogin(enterpriseCode, username, password, appVersion,
                new IJyLoginHelper.OnLoginListener() {
            @Override
            public void loginSuccess() {
                //getView().hintLoading();
                getView().LoginSuccess();
            }

            @Override
            public void loginFailed() {
                getView().hintLoading();
                getView().LoginFaile();
            }

            @Override
            public void loginException(String msg) {
                getView().hintLoading();
                getView().showLoginExpetion(msg);
            }
        });
    }

}
